/// 测试服务
// export const baseURL = 'http://114.132.124.78:8088/api/platform';
let baseURL = 'http://47.109.25.254:8070/api/platform';

/// 三院
// export const baseURL = 'http://47.109.25.254:8084/api/platform';
/// 公平
// export const baseURL = 'http://47.109.16.180:8084/api/platform'

export const setBaseURL = (url) => {
	// baseURL = url + '/api/platform';
};

export const request = (options) => {
	return new Promise((resolve, reject) => {
		const userInfo = uni.getStorageSync('userInfo')
		uni.showLoading({
			title: '加载中...'
		})
		uni.request({
			url: baseURL + options.url,
			method: options.method || 'GET',
			data: options.data || {},
			header: {
				'content-type': 'application/json',
				'token': uni.getStorageSync("userToken") || "",
				'docCode': userInfo.docCode || "",
				'orgId': userInfo.orgId || ""
			},
			success: (res) => {
				if (res.statusCode == 200) {
					if (res.data.code == 0) {
						resolve(res.data)
					} else if (res.data.code == 4) {
						reject(res.data)
						// uni.hideLoading()
						// uni.showToast({
						// 	title:"该账号已被禁用",
						// 	icon:'error'
						// })
						// console.log('改账号已经被禁用了')
						uni.showModal({
							title: '提示：',
							content: '该账号已被禁用，请联系管理员解禁',
							confirmText: '确定',
							success: () => {
								uni.clearStorageSync()
								uni.reLaunch({
									url: '/pages/login/login'
								})
							}
						})
					} else if (res.data.code == 5) {
						uni.showModal({
							title: '提示：',
							content: '手机号或账号不存在',
							confirmText: '确定',
							success: () => {
								uni.clearStorageSync()
								uni.reLaunch({
									url: '/pages/login/login'
								})
							}
						})
					} else if (res.data.code == 1007) {
						uni.showModal({
							title: '提示：',
							content: '参数错误',
							confirmText: '确定',
							success: () => {}
						})
					} else {
						reject(res)
					}

				} else {
					reject(res)
				}
				// 如果不满足上述判断就输出数据
			},
			fail: (err) => {
				console.log(err)
				reject(err)
			},
			complete() {
				uni.hideLoading()
			}
		})
	})
}